/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wisp.dataObjects;

import java.util.*;
import java.util.Vector;
import java.util.Iterator;

/**
 *
 * @author Shelley Co
 */
public class LevelUpClass 
{
    public LevelUpClass(){}
    
    public void lvlUp(Statistics wcs, WispCharacter wc, int lvl)
    {
        String cName = wcs.getCharacterName();
        this.init(wc, wcs);
        
        if(wc.getCClass().equals("templar"))
            this.lvlTemplar(wc, wcs, lvl);
        else if (wc.getCClass().equals("elementalist"))
            this.lvlElementalist(wc, wcs, lvl);
        else if (wc.getCClass().equals("heirophant"))
            this.lvlHeirophant(wc, wcs, lvl);
        
        wcs.editStat(cName, "accuracyRate", this.compACC(wcs), 0);
        wcs.editStat(cName, "atk", 0, this.compBATK(wcs));
        wcs.editStat(cName, "mAtk", 0, this.compBMATK(wcs));
        wcs.editStat(cName, "blockRate", this.compBlock(wcs), 0);
        wcs.editStat(cName, "critRate", this.compCRIT(wcs), 0);
        wcs.editStat(cName, "def", 0, this.compDEF(wcs));
        wcs.editStat(cName, "dodgeRate", this.compDodge(wcs), 0);
        wcs.editStat(cName, "res", 0, this.compRES(wcs));
        wcs.editStat(cName, "spd", this.compSPD(wcs), 0);
    }
    
    public void init(WispCharacter wc, Statistics wcs)
    {
        String cName = wcs.getCharacterName();
        
        wcs.editStat(cName, "str", 0, wcs.getStr()+1);
        wcs.editStat(cName, "dex", 0, wcs.getDex()+1);
        wcs.editStat(cName, "ints", 0, wcs.getCInt()+1);
        wcs.editStat(cName, "vit", 0, wcs.getVit()+1);
        wcs.editStat(cName, "spr", 0, wcs.getSpr()+1);
        
        int hp = (int) Math.ceil(wc.getMHP() * 1.31);
        int mp = (int) Math.ceil(wc.getMMP() * 1.25);
        
        wc.editCharInfo(cName, "maxHP", "", 0, hp);
        wc.editCharInfo(cName, "maxMP", "", 0, mp);
        
        wcs.editStat(cName, "hpGenRate", wcs.getHpGR() * 1.05, 0);
        wcs.editStat(cName, "mpGenRate", wcs.getMpGR() * 1.05, 0);
    }    
    
    public void lvlTemplar(WispCharacter wc, Statistics wcs, int lvl)
    {
        String cName = wc.getCharactername();
        
        int hp = (int) Math.ceil(wc.getMHP() * 1.02);
        
        wc.editCharInfo(cName, "maxHP", "", 0, hp);
        wcs.editStat(cName, "spd", wcs.getSpd() * 1.02, 0);
        
        if (lvl % 2 == 0) //every 2 levels
        {
            wcs.editStat(cName, "str", 0, wcs.getStr()+1);
            wcs.editStat(cName, "vit", 0, wcs.getVit()+1);
        }
        
        if (lvl % 10 == 0) //every 10th level
        {
            wcs.editStat(cName, "str", 0, wcs.getStr()+2);
            wcs.editStat(cName, "dex", 0, wcs.getDex()+2);
            wcs.editStat(cName, "vit", 0, wcs.getVit()+2);
        }
        
    }
    
    public void lvlHeirophant(WispCharacter wc, Statistics wcs, int lvl)
    {
        String cName = wc.getCharactername();
        
        int hp = (int) Math.ceil(wc.getMHP() * 1.02);
        int mp = (int) Math.ceil(wc.getMMP() * 1.02);
        
        wc.editCharInfo(cName, "maxHP", "", 0, hp);
        wc.editCharInfo(cName, "maxMP", "", 0, mp);
        
        if (lvl % 2 == 0) //every 2 levels
        {
            wcs.editStat(cName, "str", 0, wcs.getStr()+1);
            wcs.editStat(cName, "spr", 0, wcs.getSpr()+1);
        }
        
        if (lvl % 10 == 0) //every 10th level
        {
            wcs.editStat(cName, "str", 0, wcs.getStr()+2);
            wcs.editStat(cName, "spr", 0, wcs.getSpr()+2);
            wcs.editStat(cName, "vit", 0, wcs.getVit()+2);
        }
    }
    
    public void lvlElementalist(WispCharacter wc, Statistics wcs, int lvl)
    {
        String cName = wc.getCharactername();
        
        int hp = (int) Math.ceil(wc.getMHP() * 1.05);
        int mp = (int) Math.ceil(wc.getMMP() * 1.1);
        int matk = (int) Math.ceil(wcs.getMAtk() * 1.02);
        
        wc.editCharInfo(cName, "maxHP", "", 0, hp);
        wc.editCharInfo(cName, "maxMP", "", 0, mp);
        wcs.editStat(cName, "mAtk", matk, 0);
        
        if (lvl % 2 == 0) //every 2 levels
        {
            wcs.editStat(cName, "ints", 0, wcs.getCInt()+1);
            wcs.editStat(cName, "dex", 0, wcs.getDex()+1);
        }
        
        if (lvl % 10 == 0) //every 10th level
        {
            wcs.editStat(cName, "spr", 0, wcs.getSpr()+2);
            wcs.editStat(cName, "ints", 0, wcs.getCInt()+2);
            wcs.editStat(cName, "dex", 0, wcs.getDex()+2);
        }
    }
    
    public double compACC(Statistics wcs)
    {
        //null skillT
        double value = 0.0, ret = 0.0;
        double acc = 0.0;
        
        int dex = wcs.getDex();
                
        value = 0.55 + (dex * 0.0025);
        ret = (value + acc) * 100;
        System.out.println("new acc "+ ret);
        return ret;
    }
    
    public int compBATK(Statistics wcs)
    {
        double value = 0.0;
        int ret = 0;
        
        int str = wcs.getStr();
        value = (str + (5 * (str/5)));
        //value = Math.ceil(str * 1.68);
        //System.out.println("new atk value "+ value);
        ret = (int)value;
        //temp = String.valueOf(Math.floor(value));
        //ret = Integer.parseInt(temp.substring(0, temp.length()-2));
        System.out.println("new atk "+ ret);
        return ret;
    }
    
    public int compBMATK(Statistics wcs)
    {
        double value = 0.0;
        String temp = null;
        int ret = 0;
        
        int intl = wcs.getCInt();
        value = ((intl * 2) + (10 * (intl/5)));
        //value = ((intl * 2) + (6 * (intl/5)));
        
        temp = String.valueOf(Math.floor(value));
        ret = Integer.parseInt(temp.substring(0, temp.length()-2));
        
        System.out.println("new matk "+ ret);
        
        return ret;
    }
    
    
    public int compDEF(Statistics wcs)
    {
        int ret = 0;
        
        ret = (int)(wcs.getDef()*.025) + wcs.getDef();
        System.out.println("new def "+ ret);
        return ret;
    }
    
    public int compRES(Statistics wcs)
    {
        int ret = 0;
        int spr = wcs.getSpr();
        
        ret = (int)(spr * .05) + spr;
        System.out.println("new res "+ ret);
        return ret;
    }
    
    public double compDodge(Statistics wcs)
    {
        double value = 0.0, ret = 0.0;
        
        value = (1 + (wcs.getDex() / 5));
        //value = (wcs.getDex() * 1.33);
        //ret = (value) / 100;
        ret = value;
        System.out.println("new dodge "+ ret);
        return ret;
    }
    
    public double compBlock(Statistics wcs)
    {
        double value = 0.0, ret = 0.0;
        
        value = (1 + (wcs.getStr() / 5));
        //value = (wcs.getStr() * 1.47);
        //ret = (value) / 100;
        ret = value;
        System.out.println("new block "+ ret);
        return ret;
    }
    
    //is used to subtract the crit stat after the pvp/curse battle
    public double compCRIT(Statistics wcs)
    {
        double value = 0.0, ret = 0.0;
        
        int dex = wcs.getDex();
        int intl = wcs.getCInt();
             
        value = 0.01 + ((dex + intl) * 0.005);
        ret = value * 100;
        System.out.println("new crit "+ ret);
                
        return ret;
    }
    
    public double compSPD(Statistics wcs)
    {
        double value = 0.0, ret = 0.0;
        
        int dex = wcs.getDex();
        value = 0.5 + ((dex / 5) * 0.05);

        ret = value;
        System.out.println("new spd "+ ret);
        return ret;
    }
}
